package com.meetingshow.common.validator;

import java.text.ParseException;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.apache.commons.lang.time.DateUtils;

public class CustomDateValidator implements ConstraintValidator<Date, String> {
    private String pattern;

    public void initialize(Date parameters) {
        pattern = parameters.pattern();
        validateParameters();
    }

    public boolean isValid(String value,
            ConstraintValidatorContext constraintValidatorContext) {
        if (value == null) {
            return true;
        }

        try {
            DateUtils.parseDate(value, new String[] { pattern });
        } catch (ParseException e) {
            return false;
        }

        return true;
    }

    private void validateParameters() {

    }
}
